home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 90 / CD Actual 90.iso / Software3D / K-3D / k3d-0.4.2.1 / shaders / k3d_strata.sl < prev    next >
Encoding:
Text File  |  2004-07-23  |  2.6 KB  |  87 lines

  1. /*
  2.  * strata.sl -- surface shader for sedimentary rock strata
  3.  *
  4.  * DESCRIPTION:
  5.  *    Makes sedimentary rock strata, useful for rendering landscapes.
  6.  *
  7.  * PARAMETERS:
  8.  *    Ka, Kd - the usual meaning
  9.  *    txtscale - overall scaling factor for the texture
  10.  *    zscale - scaling for the thickness of the layers
  11.  *    turbscale - how turbulent the layers are
  12.  *    offset - z offset for the pattern
  13.  *    octaves - number of octaves of noise to sum for the turbulence
  14.  *
  15.  * ANTIALIASING:
  16.  *    None.
  17.  *
  18.  *
  19.  * AUTHOR:
  20.  *    C language version by F. Kenton Musgrave
  21.  *    Translation to Shading Language by Larry Gritz.
  22.  *
  23.  * REFERENCES:
  24.  *    _Texturing and Modeling: A Procedural Approach_, by David S. Ebert, ed.,
  25.  *    F. Kenton Musgrave, Darwyn Peachey, Ken Perlin, and Steven Worley.
  26.  *    Academic Press, 1994.  ISBN 0-12-228760-6.
  27.  *
  28.  * HISTORY:
  29.  *    ??? - original C language version by Ken Musgrave
  30.  *    Apr 94 - translation to Shading Language by L. Gritz
  31.  *
  32.  * this file last updated 18 Apr 1994
  33.  */
  34.  
  35. #define snoise(Pt) (2*noise(Pt) - 1)
  36.  
  37. surface k3d_strata(float Ka = 0.5, Kd = 1; float txtscale = 1;
  38.            float yscale = 2; float turbscale = 0.1; float offset = 0;
  39.            float octaves = 8;
  40.   )
  41. {
  42.   color Ct;
  43.   point PP;
  44.   float cmap;
  45.   float turb, i, freq;
  46.  
  47.   PP = txtscale * transform("shader", P);
  48.  
  49.   turb = 0;
  50.   freq = 1;
  51.   for(i = 0; i < octaves; i += 1)
  52.     {
  53.       turb += abs(snoise(PP * freq) / freq);
  54.       freq *= 2;
  55.     }
  56.  
  57.   cmap = yscale * ycomp(PP) + turbscale * turb - offset;
  58.   Ct =
  59.     color spline(mod(cmap, 1), color(166, 131, 70), color(166, 131, 70),
  60.          color(204, 178, 127), color(184, 153, 97), color(140, 114,
  61.                                   51),
  62.          color(159, 123, 60), color(204, 178, 127), color(230, 180,
  63.                                   80),
  64.          color(192, 164, 110), color(172, 139, 80), color(102, 76,
  65.                                   25),
  66.          color(166, 131, 70), color(201, 175, 124), color(181, 150,
  67.                                   94),
  68.          color(161, 125, 64), color(177, 145, 87), color(170, 136,
  69.                                  77),
  70.          color(197, 170, 117), color(180, 100, 50), color(175, 142,
  71.                                   84),
  72.          color(197, 170, 117), color(177, 145, 87), color(170, 136,
  73.                                   77),
  74.          color(186, 156, 100), color(166, 131, 70), color(188, 159,
  75.                                   104),
  76.          color(168, 134, 74), color(159, 123, 60), color(195, 167,
  77.                                  114),
  78.          color(175, 142, 84), color(161, 125, 64), color(197, 170,
  79.                                  117),
  80.          color(177, 145, 87), color(177, 145, 87)) / 255;
  81.  
  82.   /* Shade like matte, but with color scaled by cloudcolor and opacity */
  83.   Oi = 1;
  84.   Ci =
  85.     Cs * Ct * (Ka * ambient() + Kd * diffuse(faceforward(normalize(N), I)));
  86. }
  87.